import { getControllers } from './getPath.js';
import { createRouter } from './Router.js';
import Router from 'koa-router';
import bodyparser from 'koa-bodyparser';

let router = new Router();

export default (apply) => {
    // decler json object
    apply.use(bodyparser());
    // Scan controller folder
    let controllerFiles = getControllers();

    // 遍历控制器文件导入，拿到控制器参数数组注册路由
    createRouter(router, controllerFiles);
    
    console.log(`TEXT! Router: ${router}`);

    apply.use(router.routes())
}